/**
 * 车辆配置问题 - 编辑页面
 * @author miaoyl
 * @date 2018/01/14
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        vueData = {
            isIndeterminateXP: true,
            isIndeterminateBP: true,
            checkAllXP: false,
            checkAllBP: false,
            form: {
                xplist:[],
                bplist:[]
            },
            rules: {

            },
            selectOptions: {
                xp_list: [{
                    key:'1',label:'1.1'
                },{
                    key:'2',label:'2.2'
                },{
                    key:'3',label:'3.3'
                },{
                    key:'4',label:'4.4'
                }],
                bp_list: [{
                    key:'1',label:'1.1'
                },{
                    key:'2',label:'2.2'
                },{
                    key:'3',label:'3.3'
                },{
                    key:'4',label:'4.4'
                }],
                xp_list1: ['1','2','3','4'],
                bp_list1: ['1','2','3','4']
            },
        },
        pageVue,
        callObj, layOpenIndex,
        cb
    ;

    var Gwci001Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwci001_edit_gwcb013',
                _loadTplsFull: [/*{
                    dom: 'common_open_window', tpl: '/common/_open_window'
                }*/]
            }, win);
        },

        _call: function (obj) {
            pageVue.$refs['form'].resetFields();
            layOpenIndex = obj.layOpenIndex;
            callObj = obj;
            cb = obj.cb;
            vueData.isIndeterminateXP = true;
            vueData.isIndeterminateBP = true;
            vueData.checkAllXP = false;
            vueData.checkAllBP = false;
            vueData.form.bplist = [];
            vueData.form.xplist = [];
            console.log('xplist',vueData.form.xplist);
        },

        _ready: function () {
            pageVue = new Vue({
                el: '#gwci001_edit_gwcb013',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                console.log('xplist',vueData.form.xplist);
                                console.log('bplist',vueData.form.bplist);
                            }
                        });
                    },
                    handleCheckAllChangeXP:function(val) {
                        console.log('val',val);
                        console.log('vueData.form.xplist',vueData.form.xplist);
                        vueData.form.xplist = val ? vueData.selectOptions.xp_list1 : [];
                        vueData.isIndeterminateXP = false;
                    },
                    handleCheckedCitiesChangeXP:function(value) {
                        console.log('value',value);
                        let checkedCount = value.length;
                        vueData.checkAllXP = checkedCount === vueData.selectOptions.xp_list.length;
                        vueData.isIndeterminateXP = checkedCount > 0 && checkedCount < vueData.selectOptions.xp_list.length;
                        console.log('vueData.isIndeterminateXP',vueData.isIndeterminateXP);
                    },
                    handleCheckAllChangeBP:function(val) {
                        vueData.form.bplist = val ? vueData.selectOptions.bp_list1 : [];
                        vueData.isIndeterminateBP = false;
                    },
                    handleCheckedCitiesChangeBP:function(value) {
                        let checkedCount = value.length;
                        vueData.checkAllBP = checkedCount === vueData.selectOptions.bp_list.length;
                        vueData.isIndeterminateBP = checkedCount > 0 && checkedCount < vueData.selectOptions.bp_list.length;
                    }
                },
                created: function () {
                    self._setEleIsReady('gwci001_edit_gwcb013');
                },
                watch: {

                }
            });
        },

        _lazy: function () {
            this._super();
        }
    });

    return new Gwci001Edit();

});